﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using System.IO;
using Hangjing.Model;

/// <summary>
/// 提现申请
/// </summary>
public partial class shop_cachoutdetail : System.Web.UI.Page
{
    public string Picture
    {
        get
        {
            return ViewState["Picture"] == null ? "" : ViewState["Picture"].ToString();
        }
        set
        {
            ViewState["Picture"] = (object)value;
        }
    }

    protected string oldname
    {
        get
        {
            object o = ViewState["oldname"];
            return (o == null) ? "" : o.ToString();
        }
        set
        {
            ViewState["oldname"] = value;
        }
    }

    protected string oldpic
    {
        get
        {
            object o = ViewState["oldpic"];
            return (o == null) ? "" : o.ToString();
        }
        set
        {
            ViewState["oldpic"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ValidatorSet validator = new ValidatorSet("Admin");
        validator.SetValidator();
        if (!this.Page.IsPostBack)
        {
            UserHelp.IsLogin_Togo(Request.Url.PathAndQuery);


            string SqlWhere = "  1=1 and OrderStatus = 3";
            int tid = UserHelp.GetUser_Togo().Unid;
            SqlWhere += " and TogoId = " + tid + "";

            string starttime = WebUtility.InputText(Request.QueryString["starttime"]);
            if (starttime != null && starttime != "")
            {
                tbstarttime.Text = starttime;
                SqlWhere += " and  [OrderDateTime] > '" + starttime + "' ";
            }
            string endtime = WebUtility.InputText(Request.QueryString["endtime"]);
            if (endtime != null && endtime != "")
            {
                tbendtime.Text = endtime;
                SqlWhere += " and OrderDateTime < '" + endtime + " 23:59:59'";
            }

            //有交叉，不能添加
            string sqlcheckcount = " ('" + starttime + "' <= endtime) AND (starttime <= '" + endtime + "') and shopid = " + tid + " and state in (0,1)";
            if (dal.GetCount(sqlcheckcount) > 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "alert('此时间段内已经提交过申请，不能重复提交','text:添加成功!','250','150','true','3000','true','text');gourl('settlelist.aspx')");
                return;
            }


            CustorderInfo count = new Custorder().GetCountAndTotal1(SqlWhere);
            decimal nopaymoney = Convert.ToDecimal(count.CallPhoneNo.ToString());
            tbwantmoney.Text = count.CallPhoneNo.ToString();

            if (nopaymoney <= 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "alert('此时间段内没可结算的金额，请重新选择时间','text:添加成功!','250','150','true','3000','true','text');gourl('settlelist.aspx')");
                return;
            }
        }
    }

    shopcashout dal = new shopcashout();


    protected void btSave_Click(object sender, EventArgs e)
    {
        int tid = UserHelp.GetUser_Togo().Unid;
        shopcashoutInfo info = new shopcashoutInfo();
        info.cid = 0;
        info.wantmoney = Convert.ToDecimal(WebUtility.InputText(tbwantmoney.Text));
        info.shopid = tid;
        info.addtime = DateTime.Now;
        info.state = 0;
        info.remark = "";
        info.optime = Convert.ToDateTime("1970-1-1");
        info.opuser = "";
        info.reveint1 = 0;
        info.reveint2 = 0;
        info.reveint3 = 0;
        info.reveint4 = 0;
        info.reveint5 = 0;
        info.revefloat1 = 0;
        info.revefloat2 = 0;
        info.revefloat3 = 0;
        info.revevar1 = "";
        info.revevar2 = "";
        info.revevar3 = "";
        info.revevar4 = "";
        info.revevar5 = "";
        info.revetext = "";
        info.starttime = Convert.ToDateTime(WebUtility.InputText(tbstarttime.Text));
        info.endtime = Convert.ToDateTime(WebUtility.InputText(tbendtime.Text)+" 23:59:59");

        if (dal.Add(info) > 0)
        {
            AlertScript.RegScript(this, UpdatePanel1, "alert('申请成功，请等待管理员处理','text:添加成功!','250','150','true','3000','true','text');gourl('settlelist.aspx');");
        }
        else
        {
            AlertScript.RegScript(this, UpdatePanel1, "tipsWindown('提示信息','text:添加失败!','250','150','true','3000','true','text');");
        }


    }
}
